home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / on_exit.c,v < prev    next >
Encoding:
Text File  |  1992-03-27  |  2.3 KB  |  94 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    rab:1.1; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     92.03.27.13.40.40;  author rab;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* 
  26.  * on_exit.c --
  27.  *
  28.  *    This file contains the source code for the "on_exit" library
  29.  *    procedure.  "on_exit" is sort of just like "at_exit" except
  30.  *      you can pass an argument.
  31.  *
  32.  * Copyright 1988 Regents of the University of California
  33.  * Permission to use, copy, modify, and distribute this
  34.  * software and its documentation for any purpose and without
  35.  * fee is hereby granted, provided that the above copyright
  36.  * notice appear in all copies.  The University of California
  37.  * makes no representations about the suitability of this
  38.  * software for any purpose.  It is provided "as is" without
  39.  * express or implied warranty.
  40.  */
  41.  
  42. #ifndef lint
  43. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/atexit.c,v 1.4 89/03/22 00:46:53 rab Exp Locker: rab $ SPRITE (Berkeley)";
  44. #endif /* not lint */
  45.  
  46. #include <stdlib.h>
  47.  
  48. /*
  49.  * Variables shared with exit.c:
  50.  */
  51.  
  52. extern void (*_exitHandlers[])();    /* Function table. */
  53. extern int _exitNumHandlers;        /* Number of functions currently
  54.                      * registered in table. */
  55. extern long _exitHandlerArgs[];        /* Arguments to pass to functions. */
  56. extern int _exitTableSize;        /* Number of entries in table. */
  57.  
  58. /*
  59.  *----------------------------------------------------------------------
  60.  *
  61.  * on_exit --
  62.  *
  63.  *    Register a function ("func") to be called as part of process
  64.  *    exiting.  One argment can be passed.
  65.  *
  66.  * Results:
  67.  *    The return value is 0 if the registration was successful,
  68.  *    and -1 if registration failed because the table was full.
  69.  *
  70.  * Side effects:
  71.  *    Information will be remembered so that when the process exits
  72.  *    (by calling the "exit" procedure), func will be called.  Func
  73.  *    takes no arguments and returns no result.  If the process
  74.  *    terminates in some way other than by calling exit, then func
  75.  *    will not be invoked.
  76.  *
  77.  *----------------------------------------------------------------------
  78.  */
  79.  
  80. int
  81. on_exit(func, arg)
  82.     void (*func)();            /* Function to call during exit. */
  83.     long arg;
  84. {
  85.     if (_exitNumHandlers >= _exitTableSize) {
  86.     return -1;
  87.     }
  88.     _exitHandlers[_exitNumHandlers] = func;
  89.     _exitHandlerArgs[_exitNumHandlers] = arg;
  90.     _exitNumHandlers += 1;
  91.     return 0;
  92. }
  93. @
  94.